package interview.huawei.tjt.training.huaweijishi;

import java.util.Scanner;

public class Demo02 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextLine()) {
            String str = sc.nextLine();
            String[] strings = new String[str.length()];
            for (int i = 0; i < strings.length; i ++) {
                if ( str.charAt(i) != ' ' || str.charAt(i) != '+' || str.charAt(i) != '-' || str.charAt(i) != '*' || str.charAt(i) != '/'  ) {
                    strings[i] = String.valueOf(str.charAt(i));
                }
                else {
                    System.out.println("Error");
                }
            }
            if ( strings[0] == "#" || strings[0] == "$" || strings[strings.length -1] == "#" || strings[strings.length -1] == "$" ) {
                System.out.println("Error");
            } else {
                System.out.println(fun(strings));
            }
        }
    }

    public static String jisuan (String str1,String str2,String str) {
        int num1 = Integer.parseInt(str1);
        int num2 = Integer.parseInt(str2);
        int sum = 0;
        String result = null;
        switch (str) {
            case "#" :
                sum = 2*num1 + 3*num2 + 4;
                break;
            case "$" :
                sum = 3*num1 + num2 + 2;
                break;
        }
        result = String.valueOf(sum) ;
        return result;
    }

    public static int fun (String[] strings) {
        int result = 0;
        for (int i = 1; i < strings.length - 1; i ++) {
            if (strings[i] == "$") {
                strings[i - 1] = jisuan(strings[i - 1],strings[i + 1],strings[i]);
                strings[i] = "";
                strings[i + 1] = "";
                break;
            }
        }
        for (int i = 1; i < strings.length - 2; i ++ ) {
            if (strings[i] == "") {
                strings[i] = strings[i + 2];
                strings[i + 2] = "";
            }
        }
        for (int i = 1; i < strings.length -1; i ++) {
            if (strings[i] == "#") {
                strings[i - 1] = jisuan(strings[i - 1],strings[i + 1],strings[i]);
                strings[i] = "";
                strings[i + 1] = "";
                break;
            }
        }
        for (int i = 1; i < strings.length - 2; i ++ ) {
            if (strings[i] == "") {
                strings[i] = strings[i + 2];
                strings[i + 2] = "";
            }
        }

        if (strings[1] != "") {
            fun(strings);
        } else {
            result = Integer.parseInt(strings[0]);
        }
        return result;
    }

}
